﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

using Common;

namespace AdminUI.Controllers
{
    public class AccountController : Controller
    {
        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(Param_Login param)
        {
            var data = HttpHelper.HttpPost<Result<Param_AdminUser>>(Tools.ApiPath + "api/AdminUser/Login", "post", param);
            FormsAuthentication.SetAuthCookie(data.Data.AdminID.ToString(), true);
            if (data.Code==200)
            {
                FormsAuthentication.SetAuthCookie(data.Data.AdminID.ToString(), true);
                
            }
            return Json(data);
        }

        public ActionResult LogOut()
        {
            Response.Cookies["AdminName"].Expires = DateTime.Now.AddDays(-1);
            Response.Cookies["AdminPower"].Expires = DateTime.Now.AddDays(-1);
            FormsAuthentication.SignOut();
            return RedirectToAction("Login");
        }

        [HttpGet]
        public ActionResult Register()
        {
            //var result = Common.HttpHelper.HttpGet<Result<Param_AdminUser>>(Tools.ApiPath + "api/AdminUser/Find/" + id, "get");
            return View();
        }
        [HttpPost]
        public ActionResult Register(Param_AdminUser param)
        {
            //var result = Common.HttpHelper.HttpGet<Result<Param_AdminUser>>(Tools.ApiPath + "api/AdminUser/Find/" + id, "get");
            return View();
        }
    }
}